package com.example.parcelabledemo;

import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;

public class ObjBean implements Parcelable {

    private int id;
    private String name;
    private double price;
    private Bitmap bitmap;

    public ObjBean(int id, String name, double price, Bitmap bitmap)
    {
        this.id = id;
        this.name = name;
        this.price = price;
        this.bitmap = bitmap;
    };

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
    public Bitmap getBitmap() {
        return bitmap;
    }
    public void setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
    }
    public String toString() {
        return "id=" + id + ", name=" + name + ", price=" + price;
    }

    private ObjBean(Parcel in) {
        //objBean = new ObjBean();
        //objBean = in.readParcelable(ObjBean.class.getClassLoader());
        //objBean.setId(in.readInt());
        //objBean.setName(in.readString());
        //objBean.setPrice(in.readDouble());
        //objBean.setBitmap((Bitmap) in.readParcelable(Bitmap.class.getClassLoader()));

        id = in.readInt();
        name = in.readString();
        price = in.readDouble();
        bitmap = in.readParcelable(Bitmap.class.getClassLoader());

        //objBean = in.readParcelable(ObjBean.class.getClassLoader());

    }

    @Override
    public int describeContents() {
        return 0;
    }


    @Override
    public void writeToParcel(Parcel in, int flags) {
        in.writeInt(id);
        in.writeString(name);
        in.writeDouble(price);
        in.writeParcelable(bitmap, PARCELABLE_WRITE_RETURN_VALUE);

    }

    public static final Parcelable.Creator<ObjBean> CREATOR =
            new Parcelable.Creator<ObjBean>() {

                @Override
                public ObjBean createFromParcel(Parcel source) {
                    return new ObjBean(source);
                }

                @Override
                public ObjBean[] newArray(int size) {
                    return new ObjBean[size];
                }
            };



}